﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess.NHibernateHelper;
using Domain.Entity;
using DataAccess.AbstractRepository;
using NHibernate;

namespace DataAccess.Repository
{
    public class CustomerRepository : NHibRepository<Customer>, ICustomerRepository
    {
        public CustomerRepository(NHibContext context)
            : base(context)
        {
        }

        public virtual IList<Customer> GetAllCustomers(string column, string value)
        {
            string hsql = "from Customer where " + column + " like '%" + value + "%'";
            IQuery query = Session.CreateQuery(hsql);
            return query.List<Customer>();
        }

        public virtual Customer GetCustomerByEmail(string email)
        {
            Customer customer = null;
            string hsql = "from Customer where email='" + email + "'";
            IQuery query = Session.CreateQuery(hsql);
            IList<Customer> lstCustomer = query.List<Customer>();
            if (lstCustomer.Count > 0)
            {
                customer = lstCustomer.FirstOrDefault<Customer>();
            }
            return customer;
        }
    }
}
